<template>
  <!-- 内部机构维护编辑-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="editForm" :model="editForm" :rules="editRules" label-width="110px">
      <!--关联内部机构信息-->
      <el-card class="form-card orgInfo-card">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="内部机构号" prop="brno">
              <el-input
                v-model="editForm.brno"
                placeholder="内部机构号"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button
              type="primary"
              icon="el-icon-search"
              plain
              @click="brnoQry('brno')"
            >
              内部机构号查询
            </el-button>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="内部机构名称" prop="brname">
              <el-input
                v-model="editForm.brname"
                placeholder="内部机构名称"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <!--渠道信息-->
      <el-card class="form-card chnlInfo-card">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="渠道" prop="sysType">
              <el-select
                v-model="editForm.sysType"
                placeholder="渠道"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dictMap.ORGAN_SYSTYPE_BRANCH"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="渠道系统状态" prop="curSysStatus">
              <el-select
                v-model="editForm.curSysStatus"
                placeholder="渠道系统状态"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dictMap.SYSTEMSTATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="渠道系统日期" prop="curSysDate">
              <el-date-picker v-model="editForm.curSysDate" style="width: 100%;" type="date" value-format="yyyyMMdd"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入点" prop="accessPoint">
              <el-select
                v-model="editForm.accessPoint"
                placeholder="接入点"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dictMap.ACCESS_POINT"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--参与行信息-->
      <el-card class="form-card bankInfo-card">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="参与行行号" prop="bankCode">
              <el-input
                v-model="editForm.bankCode"
                placeholder="参与行行号"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button
              type="primary"
              icon="el-icon-search"
              plain
              @click="bankCodeQry('bankCode')"
            >
              我行行号查询
            </el-button>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="参与行行名" prop="orgFullName">
              <el-input
                v-model="editForm.orgFullName"
                placeholder="参与行行名"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="参与机构类别" prop="bankType">
              <el-select
                v-model="editForm.bankType"
                placeholder="参与机构类别"
                style="width: 100%"
                disabled
              >
                <el-option
                  v-for="dict in dictMap.PT_TYPE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="清算行行号" prop="drctBankCode">
              <el-input
                v-model="editForm.drctBankCode"
                placeholder="清算行行号"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="清算行行名" prop="drctBankName">
              <el-input
                v-model="editForm.drctBankName"
                placeholder="清算行行名"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所在城市代码" prop="lglCtCode">
              <el-input
                v-model="editForm.lglCtCode"
                placeholder="所在城市代码"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属CPCC" prop="lglCcpc">
              <el-input
                v-model="editForm.lglCcpc"
                placeholder="所属CPCC"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </el-form>
    <brno-search-dialog ref="brnoSearchDialog" @confirm="confirmBrno"></brno-search-dialog>
    <bank-code-search-dialog ref="bankCodeSearchDialog" @confirm="confirmBankCode"></bank-code-search-dialog >

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">提 交</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {queryBrnoUpdate,brnoUpdateSave} from "@/api/cnaps/bizMng/brnoBind.js";
import BrnoSearchDialog from "@/views/components/BrnoSearchDialog";
import { listPageMixin } from "@/libs/listPageMixin";
import BankCodeSearchDialog from "@/views/components/BankCodeSearchDialog";

export default {
  name: "brnoEdit",
  mixins: [listPageMixin],
  components: {
    BankCodeSearchDialog,
    BrnoSearchDialog,
  },
  props: {

  },
  data() {
    return {
      title: "",
      // 是否显示弹出层
      openState: false,
      // 字段可编辑控制

      //数据字典
      searchFormDictList: [
        "ORGAN_SYSTYPE_BRANCH",
        "SYSTEMSTATUS",
        "ACCESS_POINT",
        "PT_TYPE",
      ],
      // 表单参数
      editForm: {
      },
      // 表单校验
      editRules: {
        sysType: [{ required: true, message: "请选择渠道", trigger: "blur" }],
        curSysStatus: [{ required: true, message: "请选择渠道系统状态", trigger: "blur" }],
        curSysDate: [{ required: true, message: "请选择渠道系统日期", trigger: "blur" }],
        accessPoint: [{ required: true, message: "请输入接入点", trigger: "blur" }],

        brno: [{ required: true, message: "请输入内部机构", trigger: "blur" }],
        brname: [{ required: true, message: "请输入内部机构名称", trigger: "blur" }],
        bankCode: [{ required: true, message: "请输入参与行行号", trigger: "blur" }],
        orgFullName: [{ required: true, message: "请输入参与行行名", trigger: "blur" }],
        bankType: [{ required: true, message: "请选择参与机构类别", trigger: "blur" }],
        drctBankCode: [{ required: true, message: "请输入清算行行号", trigger: "blur" }],
        drctBankName: [{ required: true, message: "请输入清算行行名", trigger: "blur" }],
        lglCtCode: [{ required: true, message: "请输入所在城市代码", trigger: "blur" }],
        lglCcpc: [{ required: true, message: "请输入所属CPCC", trigger: "blur" }],
      },
      opButtonList: () => {
        return [
        ];
      },
    };
  },
  mounted() {
  },
  methods: {
    // 表单重置
    reset() {
      this.resetForm("editForm");
      this.$set(this, "editForm", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          this.reset();
          done();
        })
        .catch(_ => {});
    },
    show(row) {
      this.editForm = row;
      this.title = "内部机构维护修改";
      this.openState = true;
      this.queryBrnoUpdate(row);
    },

    brnoQry() {
      this.$refs.brnoSearchDialog.show();
    },

    queryBrnoUpdate: function(row) {
      queryBrnoUpdate(row).then(response => {
          this.editForm = response.result;
        })
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", true);
    },
    confirmBrno(fromFlag, row) {
      this.$set(this.editForm, "brno", row.brno);
      this.$set(this.editForm, "brname", row.brname);
    },

    /** TODO提交按钮 */
    submitForm: function() {
      this.$refs["editForm"].validate(valid => {
        if (valid) {
          this.submit();
        }
      });
    },

    submit() {
      brnoUpdateSave(this.editForm).then(res => {
        if (res.code === 'S') {
          this.msgSuccess("提交成功");
          this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
            confirmButtonText: "确定",
            //刷新一下查询列表
            callback: (action) => {
            },
          });
          this.cancel();
        }
      });
    },

    bankCodeQry() {
      this.$refs.bankCodeSearchDialog.show();
    },

    confirmBankCode(fromFlag, row){
      this.$set(this.editForm, "bankCode", row.bankCode);
      this.$set(this.editForm, "orgFullname", row.orgFullname);
      this.$set(this.editForm, "bankType", row.bankType);
      this.$set(this.editForm, "drctBankCode", row.drctBankCode);
      this.$set(this.editForm, "drctBankName", row.drctBankName);
      this.$set(this.editForm, "lglCtCode", row.lglCtcode);
      this.$set(this.editForm, "lglCcpc", row.lglCcpc);
    }

  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
